﻿$(function () {    
    var ywlbId = getParam("ywlbId");
    loadTop(ywlbId);
    loadTables(ywlbId);
});

function loadTop(ywlbId) {
    $("#topPic").html("");
    $("#topTitle").html("");
    $("#topAddress").html("");
    $.ajax({
        type: "GET",
        url: "/YWLB/GetByIdToJson?id=" + ywlbId + "&_t=" + new Date().getTime(),
        success: function (data) {
            $("#topTitle").html("<h4 class='weui-media-box__title'>"+data.name+"</h4>");
            $("#topPic").html("<img class='weui-media-box__thumb' src='/UploadFiles/" + data.picPath + "'>");
            $("#topAddress").html("<a href='javascript:void(0);' class='weui-media-box__desc'>办证地点：" + data.officeAddress + "</a>");
        }
    });
}

function loadTables(ywlbId) {
    $("#tableBody").html("");     
    $.ajax({
        type: "GET",
        url: "/Yw/GetYwByYwlb?ywlbId=" + ywlbId + "&_t=" + new Date().getTime(),
        success: function (data) {

            $.each(data, function (i, item) {

                var tr = "<a class='weui-cell weui-cell_access' href='/Ywlb/YwDetail?id=" + item.id + "'>" +
                    "<div class='weui-cell__bd'>" +
                        "<p>"+item.name+"</p>" +
                    "</div>" +                    
                "<div class='weui-cell__ft'></div></a>"

                $("#tableBody").append(tr);
            })
        }
    })
};

//获取URL上的参数
function getParam(paramName) {
    paramValue = "";
    isFound = false;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
        arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&");
        i = 0;
        while (i < arrSource.length && !isFound) {
            if (arrSource[i].indexOf("=") > 0) {
                if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase()) {
                    paramValue = arrSource[i].split("=")[1];
                    isFound = true;
                }
            }
            i++;
        }
    }
    return paramValue;
}